<?
error_reporting(E_ALL & ~E_NOTICE);
ini_set ("display_errors", "On");
//<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
# 根目錄
define("ROOT_DIR"	 ,str_replace("\\","/",dirname(__FILE__))."/");
# 当前执行脚本的绝对路径名
define("FILE_DIR"	 ,str_replace(ROOT_DIR,'',str_replace("\\","/",dirname($_SERVER['SCRIPT_FILENAME']))."/"));
# 配制文件的目录
define("CONFIG_DIR"	 ,ROOT_DIR."_config/");
# 内核文件目录
define("CORE_DIR"	 ,ROOT_DIR."_core/");
# 模板
define("TPL_DIR"	 ,"_tpl/");
define("TPL_ROOT_DIR",ROOT_DIR.TPL_DIR);
define("TPL_CACHE_TIME",3600);
# 包含配制文件
require CONFIG_DIR."all.conf.php";
require CONFIG_DIR."local.conf.php";
//分站配制文件
if(SUBSITE_DOMAIN || $_SERVER['HTTP_HOST'] != "www.".SITE_DOMAIN)
{//用二級域名
	$count	 = 0;
	$subSite = str_replace(SITE_DOMAIN,'',$_SERVER['HTTP_HOST'],$count);
	$subSite = $count&&$subSite?$subSite:'';
}else
{
	$subSite = A(explode('/',FILE_DIR),0);
}
$subSite 
	&& file_exists(CONFIG_DIR.$subSite.".conf.php")
	&& require CONFIG_DIR.$subSite.".conf.php";
define("SUBSITE",$subSite);
/**
 * @abstract PHP 快捷函数
 */
function &O(&$o){return $o;};
function &A(&$a,$k){return $a[$k];};
function &E($a,$t=0){trigger_error($a,$t?E_USER_ERROR:E_USER_WARNING);};
/**
 * @abstract Autoload Function
 */ 
function __autoload($class) 
{
	$filename = CORE_DIR.str_replace('_','/',$class).'.class.php';
	file_exists($filename)
		&& include_once $filename;
	ADMIN_CORE_DIR
		&& $filename = ADMIN_CORE_DIR.$class.'.class.php'
		&& file_exists($filename)
		&& include_once $filename;
	class_exists($class, false)
        || E("Unable to load class: <b>$class</b> ");
}
/**
 * 功能:类与方法路由
 */
function route($class,$method)
{
    class_exists($class)
    	|| E("NO_CLASS: <b>$class</b> ", 1);
    $Object = new $class();
    method_exists($Object,$method)
    	|| E("THIS_CLASS: <b>$class</b>  NO_METHOD: <b>$method</b> ", 1);
    $Object->$method();
    return true;
}
/**
 * 功能:得當前用戶名
 * 參數:無
 * 返回:用戶名
 */
function u_get_urs()
{
	$urs 			= $_COOKIE['urs'];
	$pass_hex		= $_COOKIE['pass_hex'];
	$login_hex 		= $_COOKIE['login_hex'];
	return (md5(substr(base64_encode($urs . SITE_LOGINKEY . $pass_hex), strlen(SITE_LOGINKEY)%5, -1)) == $login_hex)
				?$urs
				:false;
}
# 檢查是否登錄
$urs  	= u_get_urs();
#定義常量
define("urs",	$urs);
?>